# -*- coding:utf-8 -*-

import math

import BigWorld
import Math
import GUI
import csol


class RDShare:
	def __init__( self ):
		self.loadingScreenGUI = None
		self.clientSpace = None
		self.statusMgr = None
		self.cameraMgr = None
		self.cameraInUse = None
		self.controlObjMgr = None
		
rds = RDShare()



# --------------------------------------------------------------------
# other global functions
# --------------------------------------------------------------------
def setCursor( shape ):
	cursor = GUI.mcursor()
	cursor.shape = shape
	cursor.visible = True
	if not cursor.active:
		BigWorld.setCursor( cursor )

def cursorToDropPoint() :
	"""
	get three dimensionality mouse position
	@rtype				: Vector3
	@return				: position in world
	"""
	pj = BigWorld.projection()
	ly = pj.nearPlane * math.tan( pj.fov * 0.5 )
	lx = ly * BigWorld.screenWidth() / BigWorld.screenHeight()

	( cx, cy ) = csol.rcursorPosition()
	vNearPlane = Math.Vector3( lx * cx, ly * cy, pj.nearPlane )
	vNearPlane.normalise()
	vFarPlane = Math.Vector3( vNearPlane )
	vFarPlane.x *= pj.farPlane
	vFarPlane.y *= pj.farPlane
	vFarPlane.z *= pj.farPlane

	spaceID = BigWorld.player().spaceID
	camera = BigWorld.camera()
	mInvert = Math.Matrix( camera.invViewMatrix )
	vSrc = mInvert.applyToOrigin()
	vDst = mInvert.applyPoint( vFarPlane )
	vDir = Math.Vector3( vSrc - vDst )
	vDir.normalise()
	vSrc = vSrc - vDir * pj.nearPlane
	collideResult = BigWorld.collide( spaceID, vSrc, vDst, 13 )

	if collideResult is None :
		return None

	vcollide = collideResult[0]
	vcollide.y += 0.2
	dp = BigWorld.findDropPoint( spaceID, vcollide, 13 )
	if dp is None :
		return None
	return dp[0]
